package com.cy.pj.goods.dao.Impl;


import com.cy.pj.goods.dao.GoodsDao;
import com.cy.pj.goods.pojo.Goods;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


public class GoodsDaoImpl implements GoodsDao {

    @Autowired
    private SqlSession sqlSession;

    String namespace = this.getClass().getInterfaces()[0].getName();
    String elementId = Thread.currentThread().getStackTrace()[1].getMethodName();
    String statement = namespace+"."+elementId;

    @Override
    public int deleteById(Integer id) {
        return id;
    }

    @Override
    public int insertGoods(Goods goods) {
        return 0;
    }

    @Override
    public List<Goods> findGoods(){
        //String namespace="com.cy.pj.goods.dao.GoodsDao";
        //String elementId="findGoods";
        List<Goods> list=sqlSession.selectList(statement);
        return list;
    }

    @Override
    public Goods findById(Integer id) {
        Goods goods=(Goods) sqlSession.selectList(statement,id);
        return null;
    }

    @Override
    public int updateGoods(Goods goods) {
        return 0;
    }

    @Override
    public List<Goods> findByName(String name) {
        return null;
    }


}

/*public class GoodsDaoImpl implements GoodsDao {

    @Autowired
    private SqlSession sqlSession;

    String namespace = this.getClass().getInterfaces()[0].getName();
    String elementId = Thread.currentThread().getStackTrace()[1].getMethodName();
    String statement = namespace+"."+elementId;
    @Override
    public List<Goods> findGoods(){
        //String namespace="com.cy.pj.goods.dao.GoodsDao";
        //String elementId="findGoods";
        List<Goods> list=sqlSession.selectList(statement);
        return list;
    }

    @Override
    public void insert(Goods goods) {
        sqlSession.insert(statement, goods);
    }

    @Override
    public void update(Goods goods) {
        sqlSession.update(statement, goods);
    }

    @Override
    public void delete(Integer id) {
        sqlSession.delete(statement, id);
    }

    @Override
    public Goods findGoodsById(Integer id) {
        Goods goods= (Goods) sqlSession.selectList(statement,id);
        return goods;
    }
}*/
